package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.CaseDataStatus;
import cn.fintecher.pangolin.common.enums.CaseType;
import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import cn.fintecher.pangolin.service.business.model.BaseQueryRequest;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @Auther: xiaqun
 * @Description: 流转案件查询请求
 * @Date: 15:18 2020/1/3
 */

@Data
public class CirculationCaseRequest extends BaseQueryRequest {

    @ApiModelProperty(value = "案件类型")
    private CaseType caseType;

    @ApiModelProperty(value = "催收机构code")
    private String departCode;

    public BooleanBuilder getBuilder() {
        BooleanBuilder builder = generateBaseQueryBuilder();
        QCaseInfo qCaseInfo = QCaseInfo.caseInfo;
        builder.and(qCaseInfo.caseDataStatus.eq(CaseDataStatus.CIRCULATION));
        if (Objects.nonNull(this.caseType)) {
            builder.and(qCaseInfo.caseType.eq(this.caseType));
        }
        if(StringUtils.isNoneBlank(departCode)){
            builder.and(QCaseInfo.caseInfo.department.departCode.like(StringUtils.join(departCode, "%")));
        }
        return builder;
    }
}
